var getInfo = window.location.search.slice(window.location.search.lastIndexOf("?") + 1);
// console.log(getInfo);
Ajax({
    url: 'http://localhost:3000/mv/url',
    params: {
        id: getInfo,
    },
    type: 'get',
}).then(function resolve(res) {
    // console.log(res);
    let mpShow = document.querySelector('.vShow');
    const script = document.createElement('script');
    script.src = `./js/module/ckin.min.js`;
    document.head.appendChild(script);
    mpShow.innerHTML = `<video  src="${res.data.url}" style= "height: 630px" data-overlay="1"  data-color="#fff000"></video>`;
    return Ajax({
        url: 'http://localhost:3000/mv/detail',
        params: {
            mvid: getInfo,
        },
        type: 'get',
    })
}).then(function (res) {
    // console.log(res.data);
    const result = res.data;
    const vShowTitle = document.querySelector('.vShow-title');
    vShowTitle.innerHTML = `
        <h2><span class="iconfont icon-MV iconColor"></span>${result.name}</h2>
        <span>${result.artistName}</span>
    `;
})
Ajax({
    url: 'http://localhost:3000/mv/detail/info',
    params: {
        mvid: getInfo,
    },
    type: 'get',
}).then(function resolve(res) {
    // console.log(res);
    const showInfo = document.querySelector('.vShowInfo');
    showInfo.innerHTML = `
        <p><span class="iconfont icon-dianzan"></span>(${res.likedCount})</p>
        <p><span class="iconfont icon-shoucang1"></span>(${res.commentCount})</p>
        <p><span class="iconfont icon-fenxiang" style="font-size: 22px"></span>(${res.shareCount})</p>
    `;
    return Ajax({
        url: 'http://localhost:3000/simi/mv',
        params: {
            mvid: getInfo
        },
        type: 'get',
    })
}).then (function resolve (res) {
    // console.log(res.mvs);
    const mvs = document.querySelector('.similarMvs');
    template.defaults.imports.dateFormat = function(date, format){
        return date;
    };
    let tpl = template('tpl', {
        data: res.mvs,
    })
    mvs.innerHTML = tpl;
    return Ajax({
        url : 'http://localhost:3000/comment/mv',
        params: {
            id: getInfo,
            limit: 10,
        },
        type: 'get',
    })
}).then(function resolve(res) {
    console.log(res);
    let commetsAll = template('commentsAll', {
        data: res.comments,
    });
    const commentMvs = document.querySelector('.commentMvs');
    commentMvs.innerHTML = commetsAll;
    const commentAll = document.querySelector('.commentAll');
    commentAll.innerHTML = `<span>(${res.total})</span>`;
})